/*
 * CObject.cpp
 *
 *  Created on: 2011-5-4
 *      Author: subo
 */

#include "object.h"


CRuntimeClass* CRuntimeClass::pFirstClass = NULL;

static char _lpszCObject[] = "CObject";

CRuntimeClass CObject::classCObject =
  { _lpszCObject, NULL, NULL };

static AFX_CLASSINIT _init_CObject(&CObject::classCObject);


CRuntimeClass* CObject::GetRuntimeClass() const
{
  return &CObject::classCObject;
}
CObject* CRuntimeClass::CreateObject()
{
  if (m_pfnCreateObject == NULL)
  {
    return NULL;
  }
  return (*m_pfnCreateObject)();
}

CObject* CRuntimeClass::Load(const char* lpszClassName)
{
  CRuntimeClass* pClass = NULL;

  for (pClass = pFirstClass; pClass != NULL; pClass = pClass->m_pNextClass)
  {
    if (strcmp(lpszClassName, pClass->m_lpszClassName) == 0)
    {
      return pClass->CreateObject();
    }
  }
  return NULL;
}
CObject::CObject()
{
  // TODO Auto-generated constructor stub

}

CObject::~CObject()
{
  // TODO Auto-generated destructor stub
}

bool CObject::IsKindOf(const CRuntimeClass* pClass) const
{
  CRuntimeClass* pClassThis = GetRuntimeClass();
  while(pClassThis != NULL)
  {
    if(pClassThis == pClass)
    {
      return true;
    }
    else
    {
      pClassThis = pClassThis->m_pBaseClass;
    }
  }
  return false;
}

void CObject::SayHello()
{
  cout<<"CObject Constrct"<<endl;
}

AFX_CLASSINIT::AFX_CLASSINIT(CRuntimeClass* pNewClass)
{
  pNewClass->m_pNextClass = CRuntimeClass::pFirstClass;
  CRuntimeClass::pFirstClass = pNewClass;
}


